<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var nums = [10, 6, 5, 8, 5]

    var map = new Map()
    //用哈希表保存数组里的每一个数为键，若是首次创建，值为0，否则值+1
    for (const num of nums) {
      if (map.has(num)) {
        map.set(num, map.get(num) + 1)
      } else {
        map.set(num, 0)
      }
    }
    var res = []
    //遍历哈希表，找出值为0，且num+1和num-1都不是键的数
    for (const [num, count] of map) {
      if (count == 0 && !map.has(num + 1) && !map.has(num - 1)) {
        res.push(num)
      }
    }

    console.log(res)

  </script>
</body>

</html>